public member function
<ios> <iostream>

std::ios::operator bool

operator void*() const;
explicit operator bool() const;
求值流
返回是否設定了錯誤標誌(failbitbadbit)。

請注意,此函式返回的值與成員函式 good 的返回值不同,而是與成員函式 fail 的返回值相反。


如果至少設定了其中一個錯誤標誌,則函式返回空指標,否則返回其他值。
如果至少設定了其中一個錯誤標誌,則函式返回 false,否則返回 true

引數



返回值

如果設定了 failbitbadbit 中的至少一個,則返回空指標。否則返回其他值。
如果 failbitbadbit 均未設定,則返回 true
否則返回 false

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// evaluating a stream
#include <iostream>     // std::cerr
#include <fstream>      // std::ifstream

int main () {
  std::ifstream is;
  is.open ("test.txt");
  if (is) {
    // read file
  }
  else {
    std::cerr << "Error opening 'test.txt'\n";
  }
  return 0;
}

資料競爭

訪問流物件。
併發訪問同一個流物件可能導致資料爭用。

異常安全

強保證: 如果丟擲異常,流不會發生任何改變。

另見